/**
 * Created by heshufen on 20/6/27.
 */
import React, {PureComponent} from 'react';
import {TextInput} from 'react-native';

/**
 * 正文
 */
export default class Input extends PureComponent {
    focus() {
        this.refs['raw'].focus();
    }

    clear() {
        this.refs['raw'].clear();
    }

    blur() {
        this.refs['raw'].blur();
    }

    isFocused() {
        return this.refs['raw'].isFocused();
    }

    render() {
        const {style, placeholderColor, ...other} = this.props;

        const newStyle = {
            paddingLeft: 10, paddingRight: 10,
            paddingTop: 0,
            paddingBottom: 0,
            fontSize: 14, color: '#333',
        };

        if (other.multiline) {
            newStyle.textAlignVertical = 'top';
        } else {
            newStyle.textAlignVertical = 'center';
        }

        return <TextInput
            underlineColorAndroid="transparent"
            placeholderTextColor={placeholderColor}
            ref="raw"
            style={[newStyle, style]} {...other}/>;
    }
}
